//
//  RVCommonOrderManageController.swift
//  AirTravel
//
//  Created by apple on 2021/11/16.
//

import UIKit
import DNSPageView

enum RVCommonOrderType {
    case shoppingMall//商城
    case flight//机票
    case hotel//酒店
    case travel//旅游
    case railway//火车票
    case bonus//积分
}

class RVCommonOrderManageController: CommonVC {
    
    
    @IBOutlet weak var titleView: PageTitleView!
    
    @IBOutlet weak var contentView: PageContentView!
    
    var type: RVCommonOrderType
    
    init(type: RVCommonOrderType) {
        self.type = type
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        switch type {
        case .flight:
            head.title.text="机票订单"
        case .hotel:
            head.title.text="酒店订单"
        case .travel:
            head.title.text="旅游订单"
        case .railway:
            head.title.text="火车票订单"
        case .shoppingMall:
            head.title.text="商城订单"
        case .bonus:
            head.title.text="积分订单"
        }
        
        head.backgroundColor=UIColor.white
        self.view.backgroundColor=UIColor.init(hexString: "f7f7f7")
        confPageView()
    }
    func confPageView() {
        let style = PageStyle()
        style.titleViewBackgroundColor = UIColor.white
        style.isShowCoverView = false
        style.titleSelectedColor = UIColor(hexString: "#FF8A00")
        style.isShowBottomLine = true
        style.titleViewBackgroundColor = UIColor.clear
        style.isTitleScaleEnabled = true
        style.bottomLineColor = UIColor(hexString: "#FF8A00")
        style.isTitleViewScrollEnabled = true
        switch type {
        case .flight:
            confFlight(style: style)
        case .hotel:
            confHotel(style: style)
        case .travel:
            confTrvel(style: style)
        case .railway:
            confRailway(style: style)
        case .bonus:
            confBonus(style: style)
        case .shoppingMall:
            confShoppingMall(style: style)

        }

    }
    
    
    func confFlight(style: PageStyle) {
        let titles = ["待支付","已支付", "支付失败", "待出票", "已出票", "已取消", "已完成" ,"出票失败"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            var vc = UIViewController()
            if title == "待支付"{
                vc = RVFlightOrderListController(status: "0")
            }else if title == "已支付"{
                vc = RVFlightOrderListController(status: "1")
            }else if title == "支付失败"{
                vc = RVFlightOrderListController(status: "2")
            }else if title == "待出票"{
                vc = RVFlightOrderListController(status: "3")
            }else if title == "已出票"{
                vc = RVFlightOrderListController(status: "4")
            }else if title == "已取消"{
                vc = RVFlightOrderListController(status: "5")
            }else if title == "已完成"{
                vc = RVFlightOrderListController(status: "6")
            }else{
                vc = RVFlightOrderListController(status: "7")
            }
            
            addChild(vc)
            return vc
            
        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }
    
    
    func confHotel(style: PageStyle) {
        let titles = ["待支付","已支付", "支付失败", "待入住", "已入住", "已取消", "已完成" ,"待评价"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            var vc = UIViewController()
            if title == "待支付"{
                vc = RVHotelOrderListController(status: "0")
            }else if title == "已支付"{
                vc = RVHotelOrderListController(status: "1")
            }else if title == "支付失败"{
                vc = RVHotelOrderListController(status: "2")
            }else if title == "待入住"{
                vc = RVHotelOrderListController(status: "3")
            }else if title == "已入住"{
                vc = RVHotelOrderListController(status: "4")
            }else if title == "已取消"{
                vc = RVHotelOrderListController(status: "5")
            }else if title == "已完成"{
                vc = RVHotelOrderListController(status: "6")
            }else{
                vc = RVHotelOrderListController(status: "8")
            }
            
            addChild(vc)
            return vc
            
        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }

    
    func confTrvel(style: PageStyle) {
        let titles = ["待支付","已支付", "支付失败", "待出票", "已出票", "已取消", "已完成" ,"出票失败"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            var vc = UIViewController()
            if title == "待支付"{
                vc = RVFlightOrderListController(status: "0")
            }else if title == "已支付"{
                vc = RVFlightOrderListController(status: "1")
            }else if title == "支付失败"{
                vc = RVFlightOrderListController(status: "2")
            }else if title == "待出票"{
                vc = RVFlightOrderListController(status: "3")
            }else if title == "已出票"{
                vc = RVFlightOrderListController(status: "4")
            }else if title == "已取消"{
                vc = RVFlightOrderListController(status: "5")
            }else if title == "已完成"{
                vc = RVFlightOrderListController(status: "6")
            }else{
                vc = RVFlightOrderListController(status: "7")
            }
            
            addChild(vc)
            return vc
            
        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }

    
    func confRailway(style: PageStyle) {
        let titles = ["待支付","已支付", "支付失败", "待出票", "已出票", "已取消", "已完成" ,"出票失败"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            var vc = UIViewController()
            if title == "待支付"{
                vc = RVRailwayOrderListController(status: "0")
            }else if title == "已支付"{
                vc = RVRailwayOrderListController(status: "1")
            }else if title == "支付失败"{
                vc = RVRailwayOrderListController(status: "2")
            }else if title == "待出票"{
                vc = RVRailwayOrderListController(status: "3")
            }else if title == "已出票"{
                vc = RVRailwayOrderListController(status: "4")
            }else if title == "已取消"{
                vc = RVRailwayOrderListController(status: "5")
            }else if title == "已完成"{
                vc = RVRailwayOrderListController(status: "6")
            }else{
                vc = RVRailwayOrderListController(status: "7")
            }
            
            addChild(vc)
            return vc
            
        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }

    
    func confShoppingMall(style: PageStyle) {

        style.isTitleScaleEnabled = true
        style.bottomLineWidth = "已完成".getWitdhBy(font: UIFont.systemFont(ofSize: 15))+10;
//        case all//全部
//        case topay//代付款
//        case diliver//代发货
//        case accept//待收货
//        case comment//待评价
//        case finish//退款退货
        let titles = ["全部", "待付款", "待发货", "待收货", "待评价", "退款退货"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            
            if title == "全部"{
                let controller = RVMyOrderListController(type:.all)
                addChild(controller)
                return controller
            }else if title == "待付款"{
                let controller = RVMyOrderListController(type:.topay)
                addChild(controller)
                return controller
            }else if title == "待发货"{
                let controller = RVMyOrderListController(type:.diliver)
                addChild(controller)
                return controller
            }else if title == "待收货"{
                let controller = RVMyOrderListController(type:.accept)
                addChild(controller)
                return controller
            }else if title == "待评价"{
                let controller = RVMyOrderListController(type:.comment)
                addChild(controller)
                return controller
            }else{
                let controller = RVMyOrderListController(type:.finish)
                addChild(controller)
                return controller
            }

        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }
    
    func confBonus(style: PageStyle) {

        style.isTitleViewScrollEnabled = false
        style.bottomLineWidth = "已完成".getWitdhBy(font: UIFont.systemFont(ofSize: 15))+10;
//        case all//全部
//        case topay//代付款
//        case diliver//代发货
//        case accept//待收货
//        case comment//待评价
//        case finish//退款退货
        let titles = ["全部", "待发货", "待收货", "已完成"]
        // 创建每一页对应的 controller
        let _: [UIViewController] = titles.map { title -> UIViewController in
            
            if title == "全部"{
                let controller = RVBonusListController(type:.all)
                addChild(controller)
                return controller
            }else if title == "待发货"{
                let controller = RVBonusListController(type:.diliver)
                addChild(controller)
                return controller
            }else if title == "待收货"{
                let controller = RVBonusListController(type:.accept)
                addChild(controller)
                return controller
            }else{
                let controller = RVBonusListController(type:.finish)
                addChild(controller)
                return controller
            }

        }
        
        let _ = PageViewManager(style: style,
                                          titles: titles,
                                          childViewControllers: children,
                                          currentIndex: 0,
                                          titleView: titleView,
                                          contentView: contentView)
    }


}
